import * as cacheImgNoWork from "./cacheImgNoWork";
import * as  cacheImgUseWork from "./cacheImgUseWork";

let useCacheImg = cacheImgNoWork.useCacheImg
let clearImgCache = cacheImgNoWork.clearImgCache;
// 兼容可以用webwork的
if (window.Worker && window.createImageBitmap && window.OffscreenCanvas) {
  useCacheImg = cacheImgUseWork.useCacheImg
  clearImgCache = cacheImgUseWork.clearImgCache;
}

// 监听页面卸载，全部清空
window.addEventListener('beforeunload', (e) => {
  clearImgCache()
})
// 监听页面开始，全部清空
window.addEventListener('loadstart', (e) => {
  clearImgCache()
})

export {
  clearImgCache,
  useCacheImg
}
